package main

import "fmt"

// * Selection
// *The algorithm is of hhte order O(n^2)
// *This algorithm is inefficient for large collections ,and it performs worse than the insertion sort algorithm.
func SelectionSorter(elements []int) {
	var i int
	for i = 0; i < len(elements)-1; i++ {
		var min int
		min = i
		var j int
		for j = i + 1; j <= len(elements)-1; j++ {
			if elements[j] < elements[min] {
				min = j
			}
		}
		swap(elements, i, min)
	}
}

func swap(elements []int, i int, j int) {
	elements[i], elements[j] = elements[j], elements[i]
}

func main() {
	var elements []int
	elements = []int{
		1, 2, 6, 54, 3, 6, 7, 8,
	}
	fmt.Println(
		"Before sorting：", elements,
	)
	SelectionSorter(elements)
	fmt.Println(
		"After sorting：", elements,
	)
}
